﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Gencode.Common.SQL;

namespace Gencode.PrsWeb.App
{
	public class User : LoginInformation
	{
		public static User SetUserRights(string user, string password)
		{
			if (!AppGlobal.IsOdbcConection)
				AppGlobal.SetDatabaseConection();

			Querry querry = new Querry();
			querry.SetSTPName("chk_user");
			querry.AddParameter("@user", user);
			querry.AddParameter("@password", password);
			System.Data.DataView dv = querry.ExecuteForDataView();

			if (dv.Count > 0)
			{
				User ur = new User
				{
					User = user,
					Password = password,
					UserID = int.Parse(dv[0].Row[0].ToString()),
					Berechtigung = int.Parse(dv[0].Row[2].ToString()),
					Mandid = dv[0].Row[3].ToString(),
					UserName = dv[0].Row[4].ToString(),
					UserBeschreibung = dv[0].Row[5].ToString()
				};

				return ur;
			}

			return null;
		}

		public string Mandid
		{
			get;
			set;
		}
		public int UserID
		{
			get;
			private set;
		}
		public string UserName
		{
			get;
			private set;
		}
		public int Berechtigung
		{
			get;
			private set;
		}

		public string UserBeschreibung
		{
			get;
			private set;
		}
	}
}
